package gui;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class StringTest2 extends JFrame {

	private JPanel contentPane;
	private JLabel lblNewLabel;
	private JTextField input;
	private JButton check;
	private JScrollPane scrollPane;
	private JTextArea result;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					StringTest2 frame = new StringTest2();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public StringTest2() {
		setTitle("Identify Program");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		contentPane.add(getLblNewLabel());
		contentPane.add(getInput());
		contentPane.add(getCheck());
		contentPane.add(getScrollPane());
	}
	private JLabel getLblNewLabel() {
		if (lblNewLabel == null) {
			lblNewLabel = new JLabel("주민번호");
			lblNewLabel.setBounds(12, 10, 57, 15);
		}
		return lblNewLabel;
	}
	private JTextField getInput() {
		if (input == null) {
			input = new JTextField();
			input.setBounds(12, 35, 410, 21);
			input.setColumns(10);
		}
		return input;
	}
	private JButton getCheck() {
		if (check == null) {
			check = new JButton("확인");
			check.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					String year="";
					String month="";
					String day="";
					String temp="";
					year = input.getText().substring(0,2);
					month = input.getText().substring(2,4);
					day = input.getText().substring(4,6);
					temp = input.getText().substring(7,8);
					result.append("생년 : " + year);
					result.append("\n생월 : " + month);
					result.append("\n생일 : " + day);
					
					if(Integer.parseInt(temp)==1){
						result.append("\n성별 : 남자");
					}else if(Integer.parseInt(temp)==2){
						result.append("\n성별 : 여자");
					}else{
						result.append("'-'을 포함하여 주민등록번호를 입력해주세요.");
					}
					
				}
			});
			check.setBounds(12, 66, 410, 23);
		}
		return check;
	}
	private JScrollPane getScrollPane() {
		if (scrollPane == null) {
			scrollPane = new JScrollPane();
			scrollPane.setBounds(12, 99, 410, 153);
			scrollPane.setViewportView(getResult());
		}
		return scrollPane;
	}
	private JTextArea getResult() {
		if (result == null) {
			result = new JTextArea();
		}
		return result;
	}
}
